package base.sys.service;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;

import base.core.spring.BaseService;
import base.sys.api.enetity.SysDict;
import base.sys.api.enetity.SysDictItem;
import base.sys.mapper.SysDictMapper;

/**
 * @Description
 * @Author Pengwei
 * @CreatDate 2022/1/8 16:27
 */
@Service
public class SysDictService extends BaseService<SysDictMapper, SysDict> {
    @Autowired
    private SysDictItemService sysDictItemService;

    @Override
    public boolean removeById(Serializable id) {
        SysDict sysDict = this.getById(id);
        if (super.removeById(id) && StringUtils.isNotBlank(sysDict.getCode())) {
            return sysDictItemService.remove(Wrappers.<SysDictItem>lambdaQuery().eq(SysDictItem::getCode, sysDict.getCode()));
        }
        return false;
    }
}
